﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WJP.Events.Bus.Factories;
using WJP.Events.Bus.Handlers;

namespace WJP.Events.Bus
{
    /// <summary>
    /// 定义事件总线的接口。
    /// </summary>
    public interface IEventBus
    {
        #region Register

        /// <summary>
        /// 注册一个事件。
        /// <para>给定的动作被调用所有事件发生。</para>
        /// </summary>
        /// <typeparam name="TEventData">事件类型</typeparam>
        /// <param name="action"></param>
        /// <returns></returns>
        IDisposable Register<TEventData>(Action<TEventData> action) where TEventData : IEventData;

        /// <summary>
        /// 注册一个事件。
        /// <para>给定的动作被调用所有事件发生。</para>
        /// </summary>
        /// <param name="eventType">事件类型（实现IEventData的类型）</param>
        /// <param name="handler">处理事件的对象</param>
        /// <returns></returns>
        IDisposable Register(Type eventType, IEventHandler handler);

        /// <summary>
        /// 注册一个事件
        /// </summary>
        /// <param name="eventType">事件类型</param>
        /// <param name="factory">一个创建/释放处理句柄的工厂</param>
        /// <returns></returns>
        IDisposable Register(Type eventType, IEventHandlerFactory factory);

        #endregion

        #region Unregister

        /// <summary>
        /// 注销一个事件
        /// </summary>
        /// <typeparam name="TEventData">事件类型</typeparam>
        /// <param name="action"></param>
        void Unregister<TEventData>(Action<TEventData> action) where TEventData : IEventData;

        /// <summary>
        /// 注销一个事件
        /// </summary>
        /// <param name="eventType">事件类型</param>
        /// <param name="handler">之前注册过的处理事件的对象</param>
        void Unregister(Type eventType, IEventHandler handler);

        /// <summary>
        /// 注销一个事件
        /// </summary>
        /// <param name="eventType">事件类型</param>
        /// <param name="factory">事件工厂</param>
        void Unregister(Type eventType, IEventHandlerFactory factory);

        #endregion

        #region Trigger

        /// <summary>
        /// 触发一个事件
        /// </summary>
        /// <typeparam name="TEventData">事件类型</typeparam>
        /// <param name="eventData">事件相关数据</param>
        void Trigger<TEventData>(TEventData eventData) where TEventData : IEventData;

        #endregion
    }
}
